package com.exam.qc.contorller;


import com.exam.qc.client.ProductFeignClient;
import com.exam.qc.model.PageVo;
import com.exam.qc.model.Product;
import com.exam.qc.model.ReturnVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/product")
public class ProductController {

    @Resource
    private ProductFeignClient productFeignClient;


    /**
     * 分页查询产品信息接口
     * @param productName
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/search",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ReturnVo queryForPage(
            @RequestParam(value = "productName",required = true,defaultValue = "")String productName,
            @RequestParam(value = "pageNo",required = true,defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize",required = true,defaultValue = "2") Integer pageSize

    ){
       return productFeignClient.listPage(productName,pageNo,pageSize);
    }


    /**
     * 查询所有产品列表接口
     * @return
     */
    @RequestMapping(value = "/list",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ReturnVo queryProList(){
       return productFeignClient.getProList();
    }



    /**
     * 新增产品接口
     * @param product
     * @return
     */
    @RequestMapping(value = "/save",consumes = MediaType.APPLICATION_JSON_VALUE,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ReturnVo addProduct(@RequestBody Product product){
        return productFeignClient.saveProduct(product);
    }
}
